package com.Work.auth.controller;

import com.Work.auth.service.SysPostService;
import com.Work.common.result.Result;
import com.Work.model.system.SysPost;
import com.Work.vo.system.SysPostQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Api(tags = "岗位管理接口")
@RestController
@RequestMapping("/admin/system/sysPost")
public class SysPostController {

    @Autowired
    private SysPostService sysPostService;

    @ApiOperation("条件分页查询岗位列表")
    @GetMapping("{page}/{limit}")
    public Result pageQueryPost(@PathVariable Long page,
                                @PathVariable Long limit,
                                SysPostQueryVo sysPostQueryVo) {
        Map<String, Object> result = sysPostService.pageQueryPost(page, limit, sysPostQueryVo);
        return Result.ok(result);
    }

    @ApiOperation("添加岗位")
    @PostMapping("save")
    public Result save(@RequestBody SysPost post) {
        boolean isSuccess = sysPostService.save(post);
        if (isSuccess) {
            return Result.ok();
        } else {
            return Result.fail();
        }
    }

    @ApiOperation("根据 ID 查询岗位")
    @GetMapping("get/{id}")
    public Result get(@PathVariable Long id) {
        SysPost sysPost = sysPostService.getById(id);
        return Result.ok(sysPost);
    }

    @ApiOperation("修改岗位信息")
    @PutMapping("update")
    public Result update(@RequestBody SysPost post) {
        boolean isSuccess = sysPostService.updateById(post);
        if (isSuccess) {
            return Result.ok();
        } else {
            return Result.fail();
        }
    }

    @ApiOperation("根据 ID 删除岗位")
    @DeleteMapping("remove/{id}")
    public Result remove(@PathVariable Long id) {
        boolean isSuccess = sysPostService.removeById(id);
        if (isSuccess) {
            return Result.ok();
        } else {
            return Result.fail();
        }
    }

    @ApiOperation("批量删除岗位")
    @DeleteMapping("batchRemove")
    public Result batchRemove(@RequestBody java.util.List<Long> idList) {
        boolean isSuccess = sysPostService.removeByIds(idList);
        if (isSuccess) {
            return Result.ok();
        } else {
            return Result.fail();
        }
    }
}